<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro/easyui.css" />
<link rel="stylesheet" href="static/easyui/themes/icon.css" />
<title>采购管理</title>
</head>
<body>
	<script>
		$(function() {
			//搜索采购单号
			$("#procurement-ss").searchbox({
				searcher:function(value,name){
					$('#procurement-dg').datagrid({
						url : 'findall-indent',
						queryParams : {
							indentid : value
						},
						pagination : true,
						pageNumber : 1,
						pageSize : 10,
						pageList : [ 10, 20 ],
						columns : [ [ 
							{field : 'indent_id',				title : '采购单号',		width : 150}, 
							{field : 'indent_time',				title : '采购日期',		width : 150,formatter:comFormatDate}, 
							{field : 'indent_people',			title : '负责人',		width : 150},  
							{field : 'indent_allquantity',		title : '总数量',		width : 150}, 
							{field : 'indent_allmoney',			title : '总金额',		width : 150}, 
							{field : 'supplier_name',			title : '供应商',		width : 150}, 
							{field : 'indent_state',			title : '状态',			width : 146,
								 formatter : function(value,row,index){	   
					                    if(value=='0'){return '待验收'}  
					                    else if(value=='1'){return '已验收'}                        
					             } 
							}
						] ]
					});				
				}
			});
			
			//系统当前日期以后的日期、禁止选择
			$('#procurement-date1').datebox().datebox('calendar').calendar({
			    validator : function(date){
			        var now = new Date();
			        var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
			        return d1 >= date;
			    }
			});
			$('#procurement-date2').datebox().datebox('calendar').calendar({
			    validator : function(date){
			        var now = new Date();
			        var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
			        return d1 >= date;
			    }
			});
			
			//后选日期不能在前选日期之前，也不能在当前系统日期之后
			$("#procurement-date1").datebox({
			    onSelect : function(beginDate){
			        $('#procurement-date2').datebox().datebox('calendar').calendar({
			            validator: function(date){
			                var now = new Date();
			                var d1 = new Date(now.getFullYear(),now.getMonth(),now.getDate());
			                return beginDate <= date && d1 >= date;
			            }
			        });
			    }
			});
			
			$("#chadate").click(function(){
				var abc = $('#procurement-date1').val();
				var cba = $('#procurement-date2').val();
				if(abc=="" || abc==null){
					$(".drugone").text("请选择开始日期");
				 	 //清空文本
				 	$("#DRUGONE").window('open');
				   	//秒之后自动消失
				   	setTimeout(function(){
				    	 $("#DRUGONE").window('close');
					}, 1500);
				}else if(cba=="" || cba==null){
					$(".drugone").text("请选择结束日期");
				 	 //清空文本
				 	$("#DRUGONE").window('open');
				   	//秒之后自动消失
				   	setTimeout(function(){
				    	 $("#DRUGONE").window('close');
					}, 1500);
				}else{
					//采购记录
					$('#procurement-dg').datagrid({
						url : 'findall-indent',
						pagination : true,
						pageNumber : 1,
						pageSize : 10,
						singleSelect: true,
						pageList : [ 10, 20 ],
						queryParams : {
							oday : abc,
							tday : cba
						},
						columns : [ [ 
							{field : 'indent_id',				title : '采购单号',		width : 150}, 
							{field : 'indent_time',				title : '采购日期',		width : 150,formatter:comFormatDate}, 
							{field : 'indent_people',			title : '负责人',		width : 150},  
							{field : 'indent_allquantity',		title : '总数量',		width : 150}, 
							{field : 'indent_allmoney',			title : '总金额',		width : 150}, 
							{field : 'supplier_name',			title : '供应商',		width : 150}, 
							{field : 'indent_state',			title : '状态',			width : 146,
								 formatter : function(value,row,index){	   
					                    if(value=='0'){return '待验收'}  
					                    else if(value=='1'){return '已验收'}                        
					             } 
							}
						] ]
					});
				}
				
			});
			
			

			//采购记录
			$('#procurement-dg').datagrid({
				url : 'findall-indent',
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				singleSelect: true,
				pageList : [ 10, 20 ],
				columns : [ [ 
					{field : 'indent_id',				title : '采购单号',		width : 150}, 
					{field : 'indent_time',				title : '采购日期',		width : 150,formatter:comFormatDate}, 
					{field : 'indent_people',			title : '负责人',		width : 150},  
					{field : 'indent_allquantity',		title : '总数量',		width : 150}, 
					{field : 'indent_allmoney',			title : '总金额',		width : 150}, 
					{field : 'supplier_name',			title : '供应商',		width : 150}, 
					{field : 'indent_state',			title : '状态',			width : 146,
						 formatter : function(value,row,index){	   
			                    if(value=='0'){return '待验收'}  
			                    else if(value=='1'){return '已验收'}                        
			             } 
					}
				] ],
				onDblClickRow : function(rowIndex, rowData) {
					$("#procurement-win").window("open");
					//给采购单号赋值
				    $("#procurement-cgdh").textbox('setValue',rowData.indent_id);
					//给状态赋值
					if(rowData.indent_state==0){
						$("#procurement-zt").textbox('setValue',"待验收");
					}else if(rowData.indent_state==1){
						$("#procurement-zt").textbox('setValue',"已验收");
					}
					//给总金额赋值
					$("#procurement-zje").textbox('setValue',rowData.indent_allmoney);
					
					//给采购时间赋值
					var ss=rowData.indent_time;
					var tt=CurentTime(ss);
					$("#procurement-shjian").textbox('setValue',tt);					
					
					var indentid = $("#procurement-cgdh").textbox("getValue");
					
					//给采购详情获取采购单号
					$.ajax({  
                        url: 'findall-indentdetails',  
                        data:{'indentid':indentid},
                        type: 'POST',  
                        dataType:"json",
					 	success: function (data) {  
					 				//遍历数据前清空datagrid数据
					 				$('#procurementxq-dg').datagrid('loadData',{total:0,rows:[]});
					 				//循环订单商品数据
					                for ( var machine in data.result) {
					                    var row_data = {
					    					'drug_number' : data.result[machine].drug_number,
					                        'drug_name' : data.result[machine].drug_name,
					                        'drug_standard' : data.result[machine].drug_standard,
					                        'drug_purchase_price' : data.result[machine].drug_purchase_price,
					                        'indent_details_quantity' : data.result[machine].indent_details_quantity,
					                        'cgjine' : data.result[machine].drug_purchase_price*data.result[machine].indent_details_quantity
					                    };
					                    $('#procurementxq-dg').datagrid('appendRow', row_data);
					                }
					     }, 				     
                        Error: function () {  
                            alert(Error);  
                        }                   
                    });    
					
				}
			});		
			
			//采购详情
			$('#procurementxq-dg').datagrid({
				url : '',
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				pageList : [ 10, 20 ],
				columns : [ [ 
					{field : 'drug_number',					title : '药品编号',		width : 171.6},
					{field : 'drug_name',					title : '药品名称',		width : 171.6}, 
					{field : 'drug_standard',				title : '规格',			width : 171.6}, 
					{field : 'drug_purchase_price',			title : '单价',			width : 171.6}, 
					{field : 'indent_details_quantity',		title : '采购数量',		width : 171.6}, 
					{field : 'cgjine',						title : '金额',			width : 171.6} 
				] ]
			});
					
		});
		
		// 时间戳
		function CurentTime(){
	  
	        var now = new Date();
	       
	        var year = now.getFullYear();       //年
	        var month = now.getMonth() + 1;     //月
	        var day = now.getDate();            //日
	       
	        var hh = now.getHours();            //时
	        var mm = now.getMinutes();          //分
			var ss = now.getSeconds();			//秒
	       
	        var clock = year + "-";
	       
	        if(month < 10)
	            clock += "0";
	       
	        clock += month + "-";
	       
	        if(day < 10)
	            clock += "0";
	           
	        clock += day + " ";
	       
	        if(hh < 10)
	            clock += "0";
	           
	        clock += hh + ":";
	        if (mm < 10) clock += '0'; 
	        clock += mm + ":"; 
			
	        if (ss < 10) clock += '0'; 
	        clock += ss; 
	        return(clock); 
		}
		
		// 时间戳
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();//ie火狐下都可以 
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
			
	</script>
	
	<div id="procurement-p" class="easyui-panel" style="width: 100%; height: 100%; padding: 10px; background: #fafafa;"
		data-options="iconCls:'icon-save',closable:true,collapsible:true,minimizable:true,maximizable:true">
		
		<p style="height: 40px; line-height: 30px; margin-left: 40px;">
			
			<input id="procurement-date1" data-options="label:'采购日期：'"  class="easyui-datebox" style="width: 250px" />—
			
			<input id="procurement-date2" class="easyui-datebox" style="width: 170px" /> 
			
			<span style="margin-left: 20px;"></span>
			
			<a id="chadate" style="width: 60px;" class="easyui-linkbutton" >查询</a>
			
			<span style="margin-left: 50px;"></span>
			
			<input id="procurement-ss" class="easyui-textbox" style="width: 250px" data-options="label:'采购单号：'"></input>
		
		</p>

		<fieldset style="border: 1px solid #A6A6A6; border-radius: 6px; width: 1050px; margin: 0 auto; margin-top: 10px; margin-bottom: 20px;">
			
			<legend style="font-size: 17px">采购记录</legend>
			
			<table id="procurement-dg" class="logininform-table easyui-datagrid" style="width: 1030; height: 308px" 
				data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">
				
			</table>
			
		</fieldset>

		<!-- 入库记录窗口 -->
		<div id="procurement-win" class="easyui-window" title="采购详情" style="width: 1080px; height: 550px"
			data-options="iconCls:'icon-save',modal:true,closed:true,shadow:true,resizable:false,collapsible:false,minimizable:false,maximizable:false">
			
			<div class="easyui-layout" data-options="fit:true">
				
				<div data-options="region:'center'">

					<div style="width: 500; height: 60px; line-height:60px; margin-left: 60px;">
						
						<p>
							
							<input id="procurement-cgdh" class="easyui-textbox" style="width: 200px;color:#ccc" data-options="label:'采购单号：',readonly:true"></input>
							
							<span style="margin-left: 30px;"></span> 
							
							<input id="procurement-zt" class="easyui-textbox" style="width: 200px;color:#ccc" data-options="label:'状态：',readonly:true"></input>
							
							<span style="margin-left: 30px;"></span>
							
							<input id="procurement-zje" class="easyui-textbox" style="width: 200px;color:#ccc" data-options="label:'总金额：',readonly:true"></input>
							
							<span style="margin-left: 30px;"></span>
							
							<input id="procurement-shjian" class="easyui-textbox" style="width: 240px;color:#ccc" data-options="label:'采购时间：',readonly:true"></input>
													
						</p>
					
					</div>

					<div style="padding: 10px;margin-left:10px;">
						
						<table id="procurementxq-dg" class="logininform-table easyui-datagrid" style="width: 1030px; height: 308px"
							data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:false">
						
						</table>
					
					</div>
				
				</div>
			
			</div>
		
		</div>
		
		<!-- 弹框提示 -->
		<div id="DRUGONE" class="easyui-window"  title="提示框" style="width:300px;height:156px"
		    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
		          <p class="drugone" style="text-align:center;font-size: 16px;margin-top: 47px;">
		          </p>
		</div>
		
	</div>
	
</body>
</html>